package TestDemo;

class Dog {
    private int hp;

    public Dog(int hp) {
        this.hp = hp;
    }

    public Dog() {
        this.hp = 90;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }
    public boolean attack(Cat c) {
        int ac = (int)(Math.random() * 9);
        System.out.print("狗攻击猫, 造成"+ac+"点伤害, 狗当前HP为");
        c.setHp(c.getHp() - ac);
        System.out.println(c.getHp());
        if (c.getHp() <= 0) return true;
        return false;
    }

}

class Cat {
    private int hp;

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public Cat(int hp) {
        this.hp = hp;
    }

    public Cat() {
        this.hp = 80;
    }
    public boolean attack(Dog g) {
        int ac = (int)(Math.random() * 10);
        System.out.print("猫攻击狗, 造成"+ac+"点伤害, 狗当前HP为");
        g.setHp(g.getHp() - ac);
        System.out.println(g.getHp());
        if (g.getHp() <= 0) return true;
        return false;
    }
}

public class Fight {
    public static void main(String[] args) {
        Cat c = new Cat();
        Dog g = new Dog();
        while (true) {
            if (c.attack(g)) {
                System.out.println("狗HP为"+g.getHp()+"，已经失败，胜利者是猫！");
                break;
            }
            if (g.attack(c)) {
                System.out.println("猫HP为"+c.getHp()+"，已经失败，胜利者是狗！");
                break;
            }
        }
    }
}
